# Copyright 1999-2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI="2"

inherit eutils cmake-utils flag-o-matic confutils

DESCRIPTION="Multiprotocol Qt4-based instant messenger"
HOMEPAGE="http://www.qutim.org"
SRC_URI="http://www.qutim.org/uploads/src/qutim-0.2.0.tar.bz2"
LICENSE="GPL-2"

SLOT="0.2"
KEYWORDS="~amd64 ~ppc ~ppc64 ~x86"
IUSE="+icq +jabber mrim irc vkontakte twitter +histman yandexnarod +plugman floaties imagepub 
	nowlistening coder chess protocolicon weather connectioncheck nowplaying accountname 
	urlpreview kdeintegration massmessaging sqlhistory youtubedownload libnotify webhistory 
	debug"

# Используемые языки
LANGS="bg cs de ru uk"
for X in ${LANGS} ; do
	IUSE="${IUSE} linguas_${X}"
done

# Зависимости runtime
RDEPEND=">=x11-libs/qt-gui-4.5
	>=x11-libs/qt-webkit-4.5"

# Общие зависимости
DEPEND="${RDEPEND}
	>=dev-util/cmake-2.6
	!net-im/qutim:live"

# Постзависимости
PDEPEND="icq? ( x11-plugins/qutim-icq:0.2 )
        jabber? ( x11-plugins/qutim-jabber:0.2 )
        mrim? ( x11-plugins/qutim-mrim:0.2 )
	irc? ( x11-plugins/qutim-irc:0.2 )
	vkontakte? ( x11-plugins/qutim-vkontakte:0.2 )
	twitter? ( x11-plugins/qutim-twitter:0.2 )
	plugman? ( x11-plugins/qutim-plugman:0.2 )
	histman? ( x11-plugins/qutim-histman:0.2 )
	yandexnarod? ( x11-plugins/qutim-yandexnarod:0.2 )
	floaties? ( x11-plugins/qutim-floaties )
	imagepub? ( x11-plugins/qutim-imagepub )
	nowlistening? ( x11-plugins/qutim-nowlistening )
	coder? ( x11-plugins/qutim-coder )
	chess? ( x11-plugins/qutim-chess )
	protocolicon? ( x11-plugins/qutim-protocolicon )
	weather? ( x11-plugins/qutim-weather )
	connectioncheck? ( x11-plugins/qutim-connectioncheck )
	nowplaying? ( x11-plugins/qutim-nowplaying )
	accountname? ( x11-plugins/qutim-accountname )
	urlpreview? ( x11-plugins/qutim-urlpreview:0.2 )
	kdeintegration? ( x11-plugins/qutim-kdeintegration:0.2 )
	massmessaging? ( x11-plugins/qutim-massmessaging )
	sqlhistory? ( x11-plugins/qutim-sqlhistory:0.2 )
	youtubedownload? ( x11-plugins/qutim-youtubedownload )
	libnotify? ( x11-plugins/qutim-libnotify:0.2 )
	webhistory? ( x11-plugins/qutim-webhistory:0.2 )"

# Если собираем с дебагом выключаем strip бинарников
RESTRICT="mirror
	debug? ( strip )"
S=${WORKDIR}/${P}.0

pkg_setup() 
{
	# Проверки правильности задания USE флагов
	confutils_require_any icq jabber mrim irc vkontakte
	confutils_use_conflict nowlistening nowplaying
}

src_prepare()
{
	# Обработка переводов
	mv -f languages/ languages_orig
	mkdir languages
	cd languages_orig
	for FILE in * ; do
		if [[ -f ${FILE} && ${FILE} != "make.sh" ]] ; then
			cp ${FILE} ../languages
		fi
	done
	for DIR in * ; do
		DIR_CUT=${DIR:0:2}
	 	if ( [[ -d ${DIR} ]] && use linguas_${DIR_CUT} ) ; then
			mkdir ../languages/${DIR}
	 		mv -f ${DIR}/binaries/* ../languages/${DIR}
	 	fi
	done	

	# Настройка параметров сбоки
	CMAKE_IN_SOURCE_BUILD=1
	if (use debug) ; then
	unset CFLAGS CXXFLAGS
		append-flags -O1 -g -ggdb
		CMAKE_BUILD_TYPE="Debug"
	fi
	mycmakeargs="-DUNIX=1 -DBSD=0 -DAPPLE=0 -DMINGW=0 -DWIN32=0 -DPhonon=0 -DCMAKE_INSTALL_PREFIX=/usr"

	sed -i "/plugin_path +=/s/lib/$(get_libdir)/" ${S}/src/pluginsystem.cpp
}

src_install()
{
	cmake-utils_src_install

	dodir /usr/share/${PN}
	mv ${S}/languages ${D}/usr/share/${PN} || die "Failed to install locales"
}

